import axios from 'axios'

const request = axios.create({
	timeout: 5000
})

request.interceptors.request.use(config => {
	config.headers!.token = 'XXXXXXXXXXXXXXXX'
	return config
}, error => {
	return Promise.reject(error)
})

request.interceptors.response.use(response => {
	const { code } = response.data

	switch (code) {
		case 401:
			console.log('token 错误！！');
			break
		case 403:
			console.log('权限错误');
			break
		case 500:
			console.log('服务错误');
			break

	}
	return response
}, error => {
	return Promise.reject(error)
})


export default request